module.exports = function($scope, $modal, $resource, $stateParams, toaster, date2str){

    //查询机构列表
    $scope.search = function(pageNo){
        $scope.searchform.pageNo = pageNo;
        $scope.searchform.pageSize = $scope.itemsPerPage;
        if($scope.searchform.usedate == 1){
            $scope.searchform.date = date2str($scope.searchform.date);
        }
        $resource('/api/as/ggc/order/findOrderList', {}, {}).save($scope.searchform, function (res) {
            if (res.errcode === 0){
                $scope.order_list = res.data.results;
                $scope.totalItems = res.data.totalRecord;
                $scope.currentPage = pageNo;
            } else {
                toaster.error({title: '', body: '查询订单列表失败'});
            }
        });
    }

    $scope.insurance = function () {
        var modalInstance = $modal.open({
            template: require('../views/tourInsurance.html'),
            controller: 'tourInsurance',
            size: 'lg',
            resolve: {
            }
        });
        modalInstance.result.then(function (result) {
        });
    }

    init();
    function init(){
        $scope.currentPage = 1;			//当前页码
        $scope.itemsPerPage = 10;		//每页显示几条
        $scope.formData = {
            'showItem': $stateParams.type == '4' ? '3' : $stateParams.type,
            'exportFlag': $stateParams.type
        }
        $scope.searchform = {
            'usedate': 0,
            'date': date2str(new Date()),
            'open': false
        };
        $scope.ticket_state_list = [
            {'label': '全部', 'value': undefined},
            {'label': '未出票', 'value': '0'},
            {'label': '已出票', 'value': '1'},
            {'label': '已使用', 'value': '2'},
        ];
        $scope.search(1);
    }

    $scope.back = function(obj){
        $resource('/api/ac/ggc/voluntourismOrderService/updateBack', {}, {}).save({'id': obj.id}, function(res){
            if (res.errcode === 0){
                $scope.search(1);
            } else {
                toaster.error({title: '', body: '退单失败, 请重试'});
            }
        });
    }

    //打开日历空间,选择时间
    $scope.dateOpen = function($event, item){
        $event.preventDefault();
        $event.stopPropagation();
        item.opened = true;
    }

    $scope.downDate = function(){
        var modalInstance = $modal.open({
			template: require('../views/exportToExcel.html'),
			controller: 'exportToExcel',
			size: 'lg',
			resolve: {
				getDate: function () {
					return date2str;
                }
			}
		});
    }

};